import {defineStore} from "pinia"
import {ref} from 'vue'
import {userInfoService} from '@/api/user'

export const useUserStore = defineStore("user", () => {
  const token = ref('')
  const user = ref({})

  const setToken = (value) => {
    token.value = value
  }

  const removeToken = () => {
    token.value = ''
  }

  const getUser = async () => {
    const {data} = await userInfoService()
    user.value = data
  }

  const removeUser = () => {
    user.value = {}
  }

  return {
    token,
    setToken,
    removeToken,
    user,
    getUser,
    removeUser
  }
}, {persist: true})
